from _decimal import Decimal
from prettytable import PrettyTable


def decimal_format(num):
    return Decimal(num).quantize(Decimal("0.00"))


month_salary = 23000        # month salary
year_salary = 0             # year total salary
year_base_deduction = 0     # start line
year_si_deduction = 0       # social insurance
year_tax = 0


table = PrettyTable(["month", "year_salary", "year_base_deduction", "year_si_deduction", "tax_part_salary",
                     "tax_rate", "quick_deduction", "tax", "year_tax"])
for i in range(12):
    year_salary += month_salary
    year_base_deduction += 5000
    year_si_deduction += 5063
    tax_part_salary = year_salary - year_base_deduction - year_si_deduction
    if tax_part_salary < 36000:
        tax_rate = 0.03
        quick_deduction = 0
    elif tax_part_salary < 144000:
        tax_rate = 0.10
        quick_deduction = 2520
    elif tax_part_salary < 300000:
        tax_rate = 0.20
        quick_deduction = 16920
    elif tax_part_salary < 420000:
        tax_rate = 0.25
        quick_deduction = 31920
    elif tax_part_salary < 660000:
        tax_rate = 0.30
        quick_deduction = 52920
    elif tax_part_salary < 960000:
        tax_rate = 0.35
        quick_deduction = 85920
    else:
        tax_rate = 0.45
        quick_deduction = 181920
    tax = tax_part_salary * tax_rate - year_tax - quick_deduction
    year_tax += tax
    table.add_row([(i+1), year_salary, year_base_deduction, decimal_format(year_si_deduction),
                   decimal_format(tax_part_salary), decimal_format(tax_rate), quick_deduction,
                   decimal_format(tax), decimal_format(year_tax)])
    # print("month: {:2}".format(i + 1) +
    #       ", year_salary: {:7}".format(year_salary) +
    #       ", year_base_deduction: {:6}".format(year_base_deduction) +
    #       ", year_si_deduction: {:8}".format(decimal_format(year_si_deduction)) +
    #       ", tax_part_salary: {:9}".format(decimal_format(tax_part_salary)) +
    #       ", tax_rate: {:4}".format(decimal_format(tax_rate)) +
    #       ", quick_deduction: {:7}".format(quick_deduction) +
    #       ", tax: {:8}".format(decimal_format(tax)) +
    #       ", year_tax: {:8}".format(decimal_format(year_tax)) +
    #       ""
    #       )
table.align = "r"
table.align['tax_rate'] = 'c'
print(table)

"""
1	不超过36,000元的部分	         3	0
2	超过36,000元至144,000元的部分	10	2520
3	超过144,000元至300,000元的部分	20	16920
4	超过300,000元至420,000元的部分	25	31920
5	超过420,000元至660,000元的部分	30	52920
6	超过660,000元至960,000元的部分	35	85920
7	超过960,000元的部分	        45	181920
"""